#include "StdAfx.h"
#include "SControl.h"

SControl::SControl(void)
{
	m_pFont = new SFont;
	m_pParent = NULL;
}

SControl::~SControl()
{
	if (m_pFont)
	{
		delete m_pFont;
		m_pFont = NULL;
	}
}

void SControl::SetRect(SRect rc)
{
	m_rc = rc;
}

void SControl::Fresh()
{
	InvalidateRect(m_hWnd, &m_rc.ToRECT(), true);
}

void SControl::SetFocus()
{
	SWin * pWin = TheManager->FindWin(m_hWnd);
	pWin->SetFocusCtrl(this);
	OnFocus();
}

bool SControl::GetFocus()
{
	SWin * pWin = TheManager->FindWin(m_hWnd);
	SControl * pThis = this;
	return pThis == pWin->GetFocusCtrl();
}

void SControl::SetTextFont(SString strName, int nSize)
{
	m_pFont->Init(strName.GetData(), nSize);
}

LRESULT SControl::HandleMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, const void * pVoid)
{
	return 0;
}

void SControl::Paint(GII * pGii)
{}

bool SControl::Create(SString strCaption, SRect rc, SContainer * pParent)
{
	return true;
}

SSize SControl::GetStrSize(SString str)
{
	HDC hDC = GetDC(m_hWnd);
	SelectObject(hDC, m_pFont->GetFont());
	SIZE tSize = {0};
	GetTextExtentPoint32A(hDC, str.GetData(), str.GetLength(), &tSize);
	ReleaseDC(m_hWnd, hDC);
	return SSize((int)tSize.cx, (int)tSize.cy);
}

char * SControl::GetType()
{
	return "SControl";
}

bool SControl::IsType(char * pCtrlType)
{
	if (!strcmp(pCtrlType, "SControl"))
		return true;
	
	return false;
}

void FuncDefault(ThePara) {}